package cmcc.check;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class checkauth extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		String authcode1 = (String) session.getAttribute("authcode");
		String authcode2 =  request.getParameter("authcode");
		if(authcode2==null){
			authcode2="";
		}
		authcode1 = authcode1.toLowerCase();
		authcode2 = authcode2.toLowerCase();
		System.out.println(this.toString() + "------ authcode1 = "
				+ authcode1);
		System.out.println(this.toString() + "------ authcode2 = "
				+ authcode2);
		
		if (authcode1 != null && authcode2 != null
				&& authcode1.equals(authcode2)) {
			out.flush();
			out.print("OK");
		}else{
			out.flush();
			out.print("NO");
		}
	}

}
